package tech.aistar.day01.method;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/day01/get")
public class GetController extends HttpServlet {
    /**
     * 如果发送了post请求过来 -
     * HTTP Status 405 - HTTP method POST is not supported by this URL
     *
     * 只能负责处理get请求
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getMethod();
        System.out.println("get..."+method);
    }
    /**
     * 只能处理post请求
     * 如果发送了get请求 - HTTP Status 405 - HTTP method GET is not supported by this URL
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String method = req.getMethod();
//        System.out.println("post..."+method);
        this.doGet(req,resp);
    }
    /**
     * 提供了service,只会走service
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
//    @Override
//    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("service...");
//    }
}
